#include "changecity.h"
#include "ui_changecity.h"

extern QStringList list, name;

changecity::changecity(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::changecity)
{
    ui->setupUi(this);

    this->setAttribute(Qt::WA_DeleteOnClose);

    QFile file(":/settings.qss"); // 假设style.qss位于资源文件中
    if (file.open(QFile::ReadOnly))
    {
        setStyleSheet(QString(file.readAll())); // 应用全局样式
        file.close();
    }

    setWindowFlag(Qt::FramelessWindowHint,true);//去掉主窗口的边框
    setAttribute(Qt::WA_TranslucentBackground,true);//把主窗口透明

    ui->comboBox->addItems(name);

    connect(this,SIGNAL(changeCity(QString ,QString)),this->parent(),SLOT(changeCity(QString ,QString)));
}

changecity::~changecity()
{
    qDebug()<<"changecity";
    delete ui;
}


void changecity::mousePressEvent(QMouseEvent *event)
{
    if(false == ui->sureButton->underMouse() && false == ui->closeButton->underMouse() && false == ui->comboBox->underMouse())
        mouseOff = event->globalPos() - geometry().topLeft();
}

void changecity::mouseMoveEvent(QMouseEvent *event)
{
    if(false == ui->sureButton->underMouse() && false == ui->closeButton->underMouse() && false == ui->comboBox->underMouse())
        this->move(event->globalPos() - mouseOff);
}

void changecity::on_closeButton_clicked()
{
    this->close();
}


void changecity::on_sureButton_clicked()
{
    for(int i = 0; i < ::list.size(); i++)
    {
        QStringList code = ::list[i].split('\t');
        if(ui->comboBox->currentText() == code[1])
        {
            emit changeCity(code[1], code[0]);
            break;
        }
    }
}

